package fanxing.shuzu;

import org.junit.Test;

/**
 * 数组是可协变的,会记住它创建的时候存的类型
 */
public class ShuZuKeXieBian {
	public static void main(String[] args) {
        
		Object[] arr1 = new String[6];
		arr1[0] = "123";
	    System.out.println(arr1.getClass().getName()); 	      //Ljava.lang.String
		System.out.println(arr1[0].getClass().getName());     //java.lang.String

		Object[] arr2 = new Object[6];
		arr2[0] = "string";
		System.out.println(arr2.getClass().getName());   //Ljava.lang.Object
		System.out.println(arr2[0].getClass().getName());//java.lang.String


	}

	@Test
	public void test(){
		Son[] sonArray = new Son[6];
		sonArray[0] = new Son();
		Father[] fatherArray;
		fatherArray = sonArray;
		/*
		    java.lang.ArrayStoreException: fanxing.shuzu.Father
		    数组是可协变的,Father[] fatherArray = sonArray 没有任何
		    问题,但fatherArray只可以插入Son和及其子类,如果插入Father
		    就会报ArrayStoreException异常
		 */
		fatherArray[1] = new Father();
	}
}


class Father{


}

class Son extends Father{


}

class GrandSon extends Son{

}
